package com.jiyun.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiyun.feign.OrderFeignService;
import com.jiyun.feign.UserFeignService;
import com.jiyun.mapper.ChatMapper;
import com.jiyun.pojo.Chat;
import com.jiyun.pojo.DcDriver;
import com.jiyun.pojo.NCustomer;
import com.jiyun.pojo.Orders;
import com.jiyun.service.ChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ChatServiceImpl extends ServiceImpl<ChatMapper, Chat> implements ChatService {

    @Autowired
    private ChatMapper chatMapper;
    @Autowired
    private UserFeignService userFeignService;
    @Autowired
    private OrderFeignService orderFeignService;

    @Override
    public List<Chat> findchat(Integer userId, Integer driverId) {
        List<Chat> findchat = chatMapper.findchat(userId, driverId);
        List<NCustomer> one = userFeignService.findOne();
        List<DcDriver> all = orderFeignService.findD();
        for (Chat chat : findchat) {
            for (NCustomer nCustomer : one) {
                if (chat.getUserId()==nCustomer.getId()) {
                    chat.setUserName(nCustomer.getRealName());
                }
            }
            for (DcDriver dcDriver : all) {
                if (chat.getDriverId()==dcDriver.getId()) {
                    chat.setDriverName(dcDriver.getName());
                }
            }
        }
        return findchat;
    }
}
